package com.banshuibao.bsb_android.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.banshuibao.bsb_android.R;
import com.banshuibao.bsb_android.model.NewSearchResultModel;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wangpan on 2018/3/26.
 */

public class MoreTestAdapter extends BaseAdapter {

    private Context context;

    private List<NewSearchResultModel.DataBean.ExamVideosBean> list;

    public MoreTestAdapter(Context context) {
        this.context = context;
        list = new ArrayList<>();
    }

    public void upData(List<NewSearchResultModel.DataBean.ExamVideosBean> list){
        if(this.list!=null){
            this.list.addAll(list);
        }
        notifyDataSetChanged();
    }

    public void downData(List<NewSearchResultModel.DataBean.ExamVideosBean> list){
        if(this.list!=null){
            this.list.clear();
            this.list.addAll(list);
        }
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list!=null?list.size():0;
    }

    @Override
    public NewSearchResultModel.DataBean.ExamVideosBean getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView == null){
            viewHolder = new ViewHolder();
            convertView = View.inflate(context, R.layout.more_content_layout,null);
            viewHolder.content = convertView.findViewById(R.id.content);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.content.setText(list.get(position).getTitle());
        return convertView;
    }

    public class  ViewHolder {
        TextView content;
    }
}
